<template>
  <div>
    <div style="margin-bottom: 5px;">
      <el-input v-model="name" placeholder="请输入物品名" suffix-icon="el-icon-search" style="width: 200px;"
                @keyup.enter.native="loadPost"></el-input>
      <el-select v-model="storage" placeholder="请选择仓库" style="margin-left: 5px;">
        <el-option
            v-for="item in storageData"
            :key="item.id"
            :label="item.name"
            :value="item.id">
        </el-option>
      </el-select>
      <el-select v-model="goodstype" placeholder="请选择分类" style="margin-left: 5px;">
        <el-option
            v-for="item in goodstypeData"
            :key="item.id"
            :label="item.name"
            :value="item.id">
        </el-option>
      </el-select>

      <el-button type="primary" style="margin-left: 5px;" @click="loadPost">查询</el-button>
      <el-button type="success" @click="resetParam">重置</el-button>


    </div>
    <el-table :data="tableData"
              :header-cell-style="{ background: '#f2f5fc', color: '#555555' }"
              border>
      <el-table-column prop="id" label="ID" width="60">
      </el-table-column>
      <el-table-column prop="goods" label="物品名" width="100">
      </el-table-column>
      <el-table-column prop="storage" label="仓库" width="100">
      </el-table-column>
      <el-table-column prop="goodstype" label="分类" width="100">
      </el-table-column>
      <el-table-column prop="admin" label="操作人" width="100">
      </el-table-column>
      <el-table-column prop="user" label="申请人" width="100">
      </el-table-column>
      <el-table-column prop="count" label="数量" width="100">
      </el-table-column>
      <el-table-column prop="createtime" label="操作时间" width="200">
      </el-table-column>
      <el-table-column prop="remark" label="备注">
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[5, 10, 20,30]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "RecordManage",
  data() {
    return {
      user: this.$store.getters.getUser,
      storageData: [],
      goodstypeData: [],
      tableData: [],
      pageSize: 10,
      pageNum: 1,
      total: 0,
      name: '',
      storage: '',
      goodstype: '',
      centerDialogVisible: false,
      form: {
        id: '',
        name: '',
        storage: '',
        goodstype: '',
        count: '',
        remark: ''
      },
    }
  },
  created() {
    this.getStorageData()
    this.getGoodsTypeData()
    this.loadPost()
  },
  methods: {
    handleSizeChange(val) {
      this.pageNum = 1
      this.pageSize = val;
      this.loadPost();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.loadPost();
    },
    resetParam() {
      this.name = ''
      this.storage = ''
      this.goodstype = ''
      this.loadPost()
    },
    loadPost() {
      console.log(this.name, this.storage, this.goodstype)
      this.$axios.post(this.$http + '/wms/record/listPage', {
        pageSize:this.pageSize,
        pageNum:this.pageNum,
        param: {
          name: this.name ? this.name : null,
          storageId: this.storage ? this.storage : null,
          goodsTypeId: this.goodstype ? this.goodstype : null
        }
      }).then(response => {
        console.log(response.data)
        if (response.data.code === 200) {
          this.tableData = response.data.data.records
          this.total = response.data.data.total
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
    getStorageData() {
      this.$axios.get(this.$http + '/wms/storage/listAll').then(response => {
        if (response.data.code === 200) {
          this.storageData = response.data.data
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
    getGoodsTypeData() {
      this.$axios.get(this.$http + '/wms/goodstype/listAll').then(response => {
        if (response.data.code === 200) {
          this.goodstypeData = response.data.data
        } else {
          this.$message.error(response.data.message)
        }
      })
    },
  }
}
</script>

<style scoped>

</style>
